import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/models/book/BookItem.dart';
import './singleBookGridNoBar.dart';
import '../../themes/appTheme.dart';

class BookSliderGridNoBar extends StatefulWidget {
  BookSliderGridNoBar({
    Key? key,
    required this.books,
  }) : super(key: key);
  final List<BookItem> books;

  @override
  _BookSliderGridNoBar createState() => _BookSliderGridNoBar();
}

class _BookSliderGridNoBar extends State<BookSliderGridNoBar>
    with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    var books = widget.books;

    return Scaffold(
      backgroundColor: Colors.transparent,
      body: SizedBox(
        width: double.infinity,
        child: GridView.builder(
          scrollDirection: Axis.horizontal,
          itemCount: books.length,
          gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
              maxCrossAxisExtent: 340,
              childAspectRatio: 180 / 100,
              crossAxisSpacing: 9.0,
              mainAxisSpacing: 9.0),
          itemBuilder: (context, index) {
            return Container(
              padding: EdgeInsets.symmetric(horizontal: 9.0),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(3.0),
                  color: Get.isDarkMode
                      ? AppTheme.colors.darkTheme2
                      : Colors.white.withOpacity(0.3)),
              child: ClipRRect(
                child: SingleBookGridNoBar(
                  bid: books[index].bookId!,
                  btitle: books[index].bookTitle!,
                  bcode: books[index].bookCode != null
                      ? books[index].bookCode!
                      : '',
                  bimage: books[index].bookImageLink!,
                  color: books[index].color != null
                      ? books[index].color!
                      : '#808080',
                  bookLevel: books[index].bookLevel != null
                      ? books[index].bookLevel!
                      : '0',
                  viewMode: books[index].viewMode ?? 'LANDSCAPE',
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}
